package com.wing.order.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.enterprise.product.model.response.ProductPackLabelVO;
import com.wing.order.model.entity.InventoryJobLabel;
import com.wing.order.model.response.InventoryJobLabelVO;
import com.wing.order.model.response.OrderReceiveDetailVO;
import com.wing.order.model.response.OrderReceiveLabelVO;
import com.wing.order.service.InventoryJobLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Validated
@Api(value = "Admin-出/入库作业单条码管理", tags = "出/入库作业单条码管理")
@RestController("appInventoryJobLabelController")
@RequestMapping("order/app/inventoryJobLabel")
@RequiredArgsConstructor
public class InventoryJobLabelController {

    @Autowired
    private InventoryJobLabelService inventoryJobLabelService;


    @ApiOperation(value = "获取配送单明细料箱里面的条码数据", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deliveryDetailId", value = "配送单明细id", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "boxId", value = "料箱id", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/getLabelByDeliveryDetailIdBoxId")
    public JsonResult<List<InventoryJobLabelVO>> getLabelByDeliveryDetailIdBoxId(Long deliveryDetailId,Long boxId){
        return JsonResult.success(inventoryJobLabelService.getLabelByDeliveryDetailIdBoxId(deliveryDetailId,boxId));
    }

    @ApiOperation(value = "领货明细", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "demandDetailId", value = "配货需求单明细id", defaultValue = "", example = "", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public PageResult<InventoryJobLabelVO> list(
            @RequestParam(name = "page",  defaultValue = "1", required = false) Integer page
            ,@RequestParam(name = "limit",  defaultValue = "10", required = false) Integer limit
            ,@RequestParam(name = "sort",  defaultValue = "create_time", required = false) String sort
            ,@RequestParam(name = "order", defaultValue = "desc", required = false) String order
            ,Long receiveDetailId
    ) {
        Page<OrderReceiveLabelVO> pg = new Page<>(page, limit);
        Map<String, Object> params = new HashMap<>();

        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort", sort);
            params.put("order", order);
        }
        params.put("receiveDetailId",receiveDetailId);
        Page<InventoryJobLabelVO> list = inventoryJobLabelService.pageList4app(pg, params);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }
}
